package com.qzw.provider;

import com.qzw.rabbitmq.common.BaseExchangeEnum;
import com.qzw.rabbitmq.common.BaseQueueEnum;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author ：quziwei
 * @date ：Created in 2020/6/10 1:20 下午
 * @description：
 */
@Configuration
public class UserRegisterQueueConfiguration {
    @Bean
    public DirectExchange userRegisterDirectExchange()
    {
        return new DirectExchange(BaseExchangeEnum.USER_REGISTER.getValue());
    }

    /**
     * 配置用户注册队列对象实例
     * 并设置持久化队列
     * @return
     */
    @Bean
    public Queue userRegisterQueue()
    {
        return new Queue(BaseQueueEnum.USER_REGISTER.getName(),true);
    }

    /**
     * 将用户注册队列绑定到路由交换配置上并设置指定路由键进行转发
     * @return
     */
    @Bean
    public Binding userRegisterBinding()
    {
        return BindingBuilder.bind(userRegisterQueue()).to(userRegisterDirectExchange()).with(BaseQueueEnum.USER_REGISTER.getRoutingKey());
    }
}
